<?php
/* 
 * Author: Quan Van Sinh
 * Email: sinhvnb@vietnambiz.com
 */
checkLoginHeader();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA-HMw5PFb7XRfJu8BoiP7zxRMSx6L-74t-_bireyzu2YRVKubcRTX99nAo5v0P4m1Nq6z7qH1uskaSg" type="text/javascript"></script>

</head>

<body>
	<div id="container">

<script type="text/javascript">
    $(document).ready(function(){
        
    });
</script>

<div id="wrapper">
    <div id="content" style="width: 98%;">
        <b>Degrees value:</b><br />
        <input type="text" id="geocodeRoboGEO" onclick="this.select();" size="30"> <b> Click to select<b><br />
        <div id="map" style="width: 100%; height: 550px"></div>
		<div id="geo" style="width: 300px;left: 820px;top: 5px;" class="tekst">
                    <form name="setLatLon" action="googleMapLocation.php" style="padding:0px;margin:0px;">
			<br />
			<table>
				<input type="hidden" name='lat' id="frmLat">
				<input type="hidden" name='lon' id="frmLon">
			</table>
			<input type="hidden" name="setLatLon" value="Set"><br />
		</form>
		<input id="geocode" type="hidden" ><br />
        </div>
    <script type="text/javascript">
		<!--
		google_ad_client = "pub-1588116269263536";
		google_alternate_color = "FFFFFF";
		google_ad_width = 334;
		google_ad_height = 160;
		google_ad_format = "334x160_as";
		google_ad_type = "text";
		//2006-09-30: Map
		google_ad_channel ="0993881556";
		google_color_border = "DDDDDD";
		google_color_bg = "DDDDDD";
		google_color_link = "0000FF";
		google_color_text = "333333";
		google_color_url = "333333";
		//-->
		</script>
	</div>
    <script type="text/javascript">
    //<![CDATA[
	//var baseLink = "http://www.gorissen.info/Pierre/maps/googleMapLocation.php";
	//var multimapBaseLink = "http://www.multimap.com/map/browse.cgi?scale=10000&icon=x";
	var geocoder = new GClientGeocoder();
	var setLat = 21.029552;
	var setLon = 105.852520;

	// argItems code taken from
	// http://www.evolt.org/article/Javascript_to_Parse_URLs_in_the_Browser/17/14435/?format=print
	function argItems (theArgName) {
		sArgs = location.search.slice(1).split('&');
    		r = '';
    		for (var i = 0; i < sArgs.length; i++) {
        		if (sArgs[i].slice(0,sArgs[i].indexOf('=')) == theArgName) {
            			r = sArgs[i].slice(sArgs[i].indexOf('=')+1);
            			break;
        		}
    		}
    	return (r.length > 0 ? unescape(r).split(',') : '')
	}


	function getCoordForAddress(response) {

		if (!response || response.Status.code != 200) {
	        alert("Sorry, we were unable to geocode that address\n\n Sorry, dat adres bestaat blijkbaar niet!");
	    } else {
			place = response.Placemark[0];
			setLat = place.Point.coordinates[1];
			setLon = place.Point.coordinates[0];
			setLat = setLat.toFixed(6);
			setLon = setLon.toFixed(6);
			document.getElementById("frmLat").value = setLat;
			document.getElementById("frmLon").value = setLon;
		}
		placeMarker(setLat, setLon)
    }


	function placeMarker(setLat, setLon) {

		var message = "geotagged geo:lat=" + setLat + " geo:lon=" + setLon + " ";
		document.getElementById("geocode").value = message;
		var messageRoboGEO = setLat + "," + setLon + "";
                //window.opener.document.getElementById("google_map").value = messageRoboGEO;
		document.getElementById("geocodeRoboGEO").value = messageRoboGEO;

		document.getElementById("geocode").focus();
		document.getElementById("geocode").select();

		//document.getElementById("maplink").href = baseLink + "?lat=" + setLat + "&lon=" + setLon ;
		//document.getElementById("multimap").href = multimapBaseLink + "&lat=" + setLat + "&lon=" + setLon ;
		document.getElementById("frmLat").value = setLat;
		document.getElementById("frmLon").value = setLon;

		var map = new GMap(document.getElementById("map"));

		map.addControl(new GSmallMapControl()); // added
		map.addControl(new GMapTypeControl()); // added
		map.centerAndZoom(new GPoint(setLon, setLat), 2);

		var point = new GPoint(setLon, setLat);
		var marker = new GMarker(point);
		map.addOverlay(marker);

		GEvent.addListener(map, 'click', function(overlay, point) {
			if (overlay) {
				map.removeOverlay(overlay);
			} else if (point) {
				map.recenterOrPanToLatLng(point);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				var matchll = /\(([-.\d]*), ([-.\d]*)/.exec( point );
				if ( matchll ) {
					var lat = parseFloat( matchll[1] );
					var lon = parseFloat( matchll[2] );
					lat = lat.toFixed(6);
					lon = lon.toFixed(6);
					var message = "geotagged geo:lat=" + lat + " geo:lon=" + lon + " ";
					var messageRoboGEO = lat + "," + lon + "";
                                        window.opener.document.getElementById("google_map").value = messageRoboGEO;
                                        window.close();
				} else {
					var message = "<b>Error extracting info from</b>:" + point + "";
					var messagRoboGEO = message;
				}

				marker.openInfoWindowHtml(message);
				document.getElementById("geocode").value = message;
				document.getElementById("geocodeRoboGEO").value = messageRoboGEO;
				document.getElementById("geocode").focus();
				document.getElementById("geocode").select();

				document.getElementById("maplink").href = baseLink + "?lat=" + lat + "&lon=" + lon ;
				document.getElementById("multimap").href = multimapBaseLink + "&lat=" + lat + "&lon=" + lon ;
				document.getElementById("frmLat").value = lat;
				document.getElementById("frmLon").value = lon;

			}
		});
	}

	function findAddress() {
		myAddress = document.getElementById("address").value;
		geocoder.getLocations(myAddress, getCoordForAddress);

	}


	if (argItems("lat") == '' || argItems("lon") == '') {
		placeMarker(setLat, setLon);
    } else {
		var setLat = parseFloat( argItems("lat") );
		var setLon = parseFloat( argItems("lon") );
		setLat = setLat.toFixed(6);
	    setLon = setLon.toFixed(6);
		placeMarker(setLat, setLon);
    }

    //]]>
    </script>
    </div>
</body>
</html>